
//测试：多线程同时写入和读取任务
#include "../logs/maglog.hpp"
#include "bench.h"
#include <thread>
#include <fstream>
#include <iostream>
#include <chrono>

// 写日志的任务
void log_write_task(size_t thread_count, size_t msg_count, size_t msglen) {
    async_bench_thread_log(thread_count, msg_count, msglen);
}

// 读日志的任务
void log_read_task(const std::string& log_file, bool& stop_flag) {
    while (!stop_flag) {
        std::ifstream infile(log_file);
        std::string line;
        while (std::getline(infile, line)) {
            // 模拟对日志内容的处理，实际测试中可以禁用输出以减少干扰
            // std::cout << line << std::endl;
        }
        std::this_thread::sleep_for(std::chrono::milliseconds(100)); // 控制读取频率
    }
}

int main() {
    std::string log_file = "./logs/async.log";
    bool stop_flag = false;

    // 启动日志写入任务
    std::thread write_thread(log_write_task, 5, 1000000, 100);

    // 启动日志读取任务
    std::thread read_thread(log_read_task, log_file, std::ref(stop_flag));

    // 等待写日志任务完成
    write_thread.join();

    // 设置停止标志，结束读取任务
    stop_flag = true;
    read_thread.join();

    return 0;
}
